<template>
  <el-dialog
    :title="!dataForm.id ? '调资依据' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="调资依据（增加退休费文件名和文号）" prop="tzgj" label-width="180px">
      <el-input
        type="textarea"
        :autosize="{ minRows: 4, maxRows: 10 }"
        v-model="dataForm.tzgj"
        placeholder="备注"
        :style="{ width: '95%' }"
      >
      </el-input>
    </el-form-item>
    <el-form-item label="补发月数（按文件增加退休费日期）" prop="bfys" label-width="180px">
      <el-input v-model="dataForm.bfys" ></el-input>
    </el-form-item>
    <el-form-item label="注意：补发月数为当前日期月数，下月发放时已经是增加后的标准" prop="bfys" label-width="440px">
      
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          tzgj: '',
          bfys: ''
        },
        dataRule: {
          tzgj: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          bfys: [
            { required: true,  pattern: /^[0-9]*$/,message: "请输入数字", }
          ]
        }
      }
    },
    methods: {
      init () {
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
            this.$http({
              url: this.$http.adornUrl(`/jxxm/adjustmentbasis/infoList`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.id = data.adjustmentBasis.id
                this.dataForm.tzgj = data.adjustmentBasis.tzgj
                this.dataForm.bfys = data.adjustmentBasis.bfys
              }
            })
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/jxxm/adjustmentbasis/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'tzgj': this.dataForm.tzgj,
                'bfys': this.dataForm.bfys
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
